<template>
  <div class="page-search">
    <el-card class="box-card">
      <el-row :gutter="10">
        <el-form :model="searchForm" label-width="120px" ref="searchRef">
          <el-col :xs="24" :sm="12" :md="8" :lg="6">
            <el-form-item label="用户名">
              <el-input v-model="searchForm.uid" placeholder="请输入用户名" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8" :lg="6">
            <el-form-item label="权限名称">
              <el-select v-model="searchForm.role" placeholder="请选择权限名称">
                <template v-for="item in sysuserList" :key="item.role">
                  <el-option :label="item.role" :value="item.role" />
                </template>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>

      <div class="footer">
        <el-button type="primary" @click="handelSubmit" :icon="Search">搜索</el-button>
        <el-button @click="handelReset">重置</el-button>
      </div>
    </el-card>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { Search } from '@element-plus/icons-vue';
import type { FormInstance } from 'element-plus';
import useBaseStore from '@/store/main';
import { storeToRefs } from 'pinia';

const emit = defineEmits(['onQuery', 'onReset']);

interface IsearchForm {
  uid: string;
  role: string;
}

const searchForm = ref<IsearchForm>({
  uid: '',
  role: ''
});

const searchRef = ref<FormInstance>();

const baseStore = useBaseStore();
const { sysuserList } = storeToRefs(baseStore);

const handelSubmit = () => {
  emit('onQuery', searchForm.value);
};

const handelReset = () => {
  searchRef.value?.resetFields();
  searchForm.value = {} as any;
  emit('onReset');
};
</script>

<style lang="less" scoped>
.page-search {
  .el-row {
    width: 100%;

    .el-form {
      width: 100%;
      display: flex;
      flex-wrap: wrap;
    }
  }

  .footer {
    display: flex;
    justify-content: flex-end;
  }
}
</style>
